<?php
  // no direct access
  defined( '_JEXEC' ) or die( 'Restricted access' );
  jimport( 'joomla.application.component.view');
  
  class VideoViewVideo extends JView
  {              
    var $_name = "video";
  
    function display()
    { 
      $this->displayList();
    }
    
    function displayList()
    {
      /* sorting */
      $state =& $this->get( 'state' );
            $lists['order_Dir'] = $state->get($this->_name . 'filter_order_Dir');
            $lists['order']     = $state->get($this->_name . 'filter_order');
            $this->assignRef('lists', $lists);    
    
      $videos = $this->get('ListData');
      if(empty($videos))
        $videos = array();
      
      $videos = $this->prepare_videos($videos);
      $this->assign('videos', $videos);
      
      $this->assign('videos', $videos);  
      $pagination = $this->get('Pagination');
      $this->assign('pagination', $pagination);
      
      JToolBarHelper::title( JText::_( 'Videos' ), 'generic.png' );
      
      JToolBarHelper::publishList();
      JToolBarHelper::unpublishList();
      JToolBarHelper::addNew();
      JToolBarHelper::editList();
      JToolBarHelper::deleteList();
      
      PBNYHelper::createMenu();
      
      parent::display("list");    
    }
    
    private function prepare_videos($videos){
      
      $mvideo = $this->getModel('video');
      
      foreach($videos as $video){
        $video->instance  = strtoupper($mvideo->get_video_type_instance($video->video_type, $video->video_id));
        $video->thumbnail = $mvideo->get_video_thumbnail($video->video);
      }
      
      return $videos;
    }
    
    function displayAdd()
    {  
      $mvideo  = $this->getModel('video');    
      
      $this->assign("video_types", $mvideo->get_video_types());
      
      JToolBarHelper::title( JText::_( 'Add Video' ), 'generic.png' );
      JToolBarHelper::save();
      JToolBarHelper::cancel();

      parent::display("edit");
    }    
    
    function displayEdit()
    {  
      $mvideo  = $this->getModel('video');
      
      $cids  = JRequest::getVar('cid', null, 'default', 'array' );
      $video = $mvideo->get($cids[0]);
      $video->video_embed = $mvideo->get_video_embed($video->video);
      
      $this->assign("video", $video);
      $this->assign("video_types", $mvideo->get_video_types());
      $this->assign("video_type_instances", $mvideo->get_video_type_instances($video->video_type));
      
      JToolBarHelper::title( JText::_( 'Edit Video' ), 'generic.png' );
      JToolBarHelper::save();
      JToolBarHelper::cancel();  

      parent::display("edit");
    }
  }
?>